﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace HY.BLL.sys
{
    public class chkpw
    {

        /// <summary>
        /// 检测用户密码
        /// </summary>
        /// <param name="nm"></param>
        /// <param name="pw"></param>
        /// <returns></returns>
        public static bool chkpassword(string nm, string pw)
        {
            if (nm == "" || pw == "") return false;

            pw = Md5(pw);
            string sqltxt = "select sid from sys_user where lgid='" + nm + "' and lgpw='" + pw + "'";
            return DAL.DbHelperSQL.Exists(sqltxt);


        }

        public static string Md5(string str)
        {
            int code = 16;
            //str = System.Web.HttpUtility.UrlEncode(str); 
            if (code == 16) //16位MD5加密（取32位加密的9~25字符） 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
            }
            else//32位加密 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            }

        }

    }
}
